/*
 * 此程序由帅气的李老师于2019.7.9编写
 * （由强迫症的韩宇航小朋友稍作排版）  
 */
 
 #include<SoftwareSerial.h>

 SoftwareSerial BT(10,11);
 char val;

 int in3 = 4;
 int in4 = 5;
 int in1 = 2;        
 int in2 = 3; 

 int hin3 = 8;
 int hin4 = 9;
 int hin1 = 6;         
 int hin2 = 7;
 
 void setup() {
 Serial.begin(9600);
 BT.begin(9600);
 pinMode(in3,OUTPUT);
 pinMode(in4,OUTPUT);
 pinMode(in1,OUTPUT);
 pinMode(in2,OUTPUT);

 pinMode(hin3,OUTPUT);
 pinMode(hin4,OUTPUT);
 pinMode(hin1,OUTPUT);
 pinMode(hin2,OUTPUT);

 }

 void loop() 
 {
  if(BT.available())
  {
    val = BT.read();
    if(val =='1')
    {
      go();
      delay(150);
      ting();
      }
      else if(val =='2')
    {
      back();
      delay(150);
      ting();
      }
       else if(val =='3')
    {
      left();
      delay(75);
      ting();
      }
       else if(val =='4')
    {
      right();
      delay(75);
      ting();
      }
    
    }
 }
 void go()
 { 
  digitalWrite(in3,LOW);
  digitalWrite(in4,HIGH);
  digitalWrite(in1,LOW);
  digitalWrite(in2,HIGH);

  digitalWrite(hin3,HIGH);
  digitalWrite(hin4,LOW);
  digitalWrite(hin1,HIGH);
  digitalWrite(hin2,LOW);
 }
 void ting()
 {
  digitalWrite(in3,HIGH);
  digitalWrite(in4,HIGH);
  digitalWrite(in1,HIGH);
  digitalWrite(in2,HIGH);

  digitalWrite(hin3,HIGH);
  digitalWrite(hin4,HIGH);
  digitalWrite(hin1,HIGH);
  digitalWrite(hin2,HIGH);
 }
 void back()
 {
  digitalWrite(in3,HIGH);
  digitalWrite(in4,LOW);
  digitalWrite(in1,HIGH);
  digitalWrite(in2,LOW);

  digitalWrite(hin3,LOW);
  digitalWrite(hin4,HIGH);
  digitalWrite(hin1,LOW);
  digitalWrite(hin2,HIGH);
 }
 void left()
 {
  digitalWrite(in3,LOW);
  digitalWrite(in4,HIGH);
  digitalWrite(in1,LOW);
  digitalWrite(in2,HIGH);

  digitalWrite(hin3,HIGH);
  digitalWrite(hin4,LOW);
  digitalWrite(hin1,HIGH);
  digitalWrite(hin2,HIGH);
 }
 void right()
 {
  digitalWrite(in3,LOW);
  digitalWrite(in4,HIGH);
  digitalWrite(in1,LOW);
  digitalWrite(in2,HIGH);

  digitalWrite(hin3,HIGH);
  digitalWrite(hin4,HIGH);
  digitalWrite(hin1,HIGH);
  digitalWrite(hin2,LOW);
 }
